<?php
class Classes_model extends CI_Model
{
	public function __construct()
	{
		$this->load->database();
	}	
	
	public function get_classes($level = FALSE)
	{
		$this->db->select('classes.name AS name , levels.name AS level');
		$this->db->from('classes');
		$this->db->order_by('levels.id ASC, classes.name ASC');
		$this->db->join('levels', 'classes.level = levels.id');		
		if ($level !== FALSE)
		{
			$this->db->where('classes', array('level' => $level));
		}
		$query =  $this->db->get();
		return $query->result_array();
	}

	public function set_classes()
	{
		$data = array(
			'name' => $this->input->post('name'),
			'level' => $this->input->post('level'),
			'room' => $this->input->post('room')
		);
		
		return $this->db->insert('classes', $data);
	}	
}